package com.hw.protocol.tool.decode.hb;

import com.hw.protocol.tool.model.entity.hb.Flower;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

/**
 * @author : lihy
 * @date : 2023/11/2 17:01
 * description: 流量计实时数据解码器
 */
public class FlowerDecode {

    private ByteBuf dataBuf;

    private Flower flower;

    public FlowerDecode(String devSerial, byte[] data) {
        this.dataBuf = Unpooled.wrappedBuffer(data);
        flower = new Flower();
        flower.setDevSerial(devSerial);
    }

    public Flower buildObject() {
        flower.setChunnelSerial(dataBuf.readByte());
        flower.setTime(DecodeUtil.getTime(dataBuf));
        flower.setMeterType(dataBuf.readShortLE());
        if (flower.getMeterType() != 0) {
            flower.setPress(dataBuf.readFloatLE());
            flower.setTemperature(dataBuf.readFloatLE());
            flower.setRealFlux(dataBuf.readFloatLE());
            flower.setRealVolume(dataBuf.readDoubleLE());
            flower.setFlux(dataBuf.readFloatLE());
            flower.setVolume(dataBuf.readDoubleLE());
            flower.setRatio(dataBuf.readFloatLE());
            flower.setFactor(dataBuf.readFloatLE());
            flower.setStatus(dataBuf.readShortLE());
            flower.setSignal(dataBuf.readByte());
            flower.setUploadType(dataBuf.readByte());
        }
        dataBuf.release();

        return flower;
    }

}
